<?php
	
	Database::ExecuteCreateStandardTable('test_conversions'
		,'xid',Sql::ID
		,'xstring',Sql::String100
		,'xboolean',Sql::Boolean
		,'xinteger',Sql::Integer
		,'xdate',Sql::DateTime
		,'xtime',Sql::Time
		,'xtimespan',Sql::TimeSpan
		);
	Database::ExecuteInsert('test_conversions');

	$dr = Database::Execute('SELECT * FROM test_conversions');
	while ($dr->Read()){
		Test::Begin('DBValue NULL Sql::ID -> ID');
		Test::AssertEqual(null, $dr['xid']->AsID());
		
		Test::Begin('DBValue NULL Sql::String100 -> String');
		Test::AssertEqual(null,$dr['xstring']->AsString());
		
		Test::Begin('DBValue NULL Sql::Boolean -> Boolean');
		Test::AssertEqual(false,$dr['xboolean']->AsBoolean());

		Test::Begin('DBValue NULL Sql::Boolean -> Nullable Boolean');
		Test::AssertEqual(null,$dr['xboolean']->AsNullableBoolean());
		
		Test::Begin('DBValue NULL Sql::Integer -> Integer');
		Test::AssertEqual(false,$dr['xinteger']->AsInteger());

		Test::Begin('DBValue NULL Sql::Integer -> Nullable Integer');
		Test::AssertEqual(null,$dr['xinteger']->AsNullableInteger());
		
		Test::Begin('DBValue NULL Sql::DateTime -> DateTime');
		Test::AssertEqual(null,$dr['xdate']->AsDateTime());
		
		Test::Begin('DBValue NULL Sql::Time -> Time');
		Test::AssertEqual(null,$dr['xtime']->AsTime());
		
		Test::Begin('DBValue NULL Sql::TimeSpan -> TimeSpan');
		Test::AssertEqual(null,$dr['xtimespan']->AsTimeSpan());
	}
	$dr->Close();

	
	$d = ImmutableDateTime::Make(2000,01,02,12,13,14);
	$t = ImmutableTimeSpan::Make(1,2,3,4);
	Database::ExecuteUpdateAll('test_conversions'
		,'xid',10
		,'xstring','test'
		,'xboolean',1
		,'xinteger',10
		,'xdate',$d
		,'xtime',$d->GetTime()
		,'xtimespan', $t
		);


	$dr = Database::Execute('SELECT * FROM test_conversions');
	while ($dr->Read()){
		Test::Begin('DBValue Sql::ID -> ID');
		Test::AssertEqual(10, $dr['xid']->AsID()->AsInt());
		
		Test::Begin('DBValue Sql::String100 -> String');
		Test::AssertEqual('test', $dr['xstring']->AsString());
		
		Test::Begin('DBValue Sql::Boolean -> Boolean');
		Test::AssertEqual(true, $dr['xboolean']->AsBoolean());

		Test::Begin('DBValue Sql::Boolean -> Nullable Boolean');
		Test::AssertEqual(true, $dr['xboolean']->AsNullableBoolean());
		
		Test::Begin('DBValue Sql::Integer -> Integer');
		Test::AssertEqual(10, $dr['xinteger']->AsInteger());

		Test::Begin('DBValue Sql::Integer -> Nullable Integer');
		Test::AssertEqual(10, $dr['xinteger']->AsNullableInteger());
		
		Test::Begin('DBValue Sql::DateTime -> DateTime');
		Test::AssertEqual($d->AsInt(), $dr['xdate']->AsDateTime()->AsInt());
		
		Test::Begin('DBValue Sql::Time -> Time');
		Test::AssertEqual($d->GetTime()->AsInt(), $dr['xtime']->AsTime()->AsInt());
		
		Test::Begin('DBValue Sql::TimeSpan -> TimeSpan');
		Test::AssertEqual($t->AsInt(), $dr['xtimespan']->AsTimeSpan()->AsInt());
	}

?>
